#!bin/bash

# user environment
CONFIG=~/.bashrc

source $CONFIG

# current dir
BaseDir=$(cd $(dirname $0);pwd -P)

HADOOP_PACK_FILE=hadoop-3.3.4.tar.gz

RELATIVE_EXTRAC_DIR=hadoop-3.3.4

if [ ! -d ${RELATIVE_EXTRAC_DIR} ];then
	# get hadoop bin compressed file
	wget https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/stable/hadoop-3.3.4.tar.gz
	echo "hadoop not existed"
	mkdir -p ${RELATIVE_EXTRAC_DIR}
	tar xvf ${HADOOP_PACK_FILE}
fi

HADOOP_HOME=${BaseDir}/${RELATIVE_EXTRAC_DIR}


if [ -z "$( export | grep HADOOP_HOME )" ];then
	echo "hadoop env not existed, to create"
	echo 'export HADOOP_HOME='${HADOOP_HOME} >> $CONFIG
	TPATH='$PATH:'${HADOOP_HOME}/bin
    	echo 'export PATH='$TPATH >> $CONFIG
	TPATH='$PATH:'${HADOOP_HOME}/sbin
	echo 'export PATH='$TPATH >> $CONFIG
fi 

mkdir -p ~/input
